//
//  Dispatcher.swift
//  test-ios
//
//  Created by wyz5204 on 2023/6/19.
//

import Foundation

class Dispatcher {
    
    static let work = DispatchQueue.init(label: "Work")
    
    static func dispatchWorkClosure(delayTime : TimeInterval = 0 ,dispatch : DispatchQueue = work , _ closure : @escaping () -> Void){
        dispatchClosure(delayTime: delayTime,dispatch: dispatch ,closure)
    }
    //delayTime：延时时间。比如：.seconds (3)、 .milliseconds (300)
    //qosClass：使用的全局Q0S类（默认为 nil，表示主线程）
    //closure:延迟运行的代码
    static func dispatchClosure(delayTime : TimeInterval = 0 ,dispatch : DispatchQueue = .main , _ closure : @escaping () -> Void){
        if(delayTime.isZero){
            dispatch.async(execute: closure)
            return
        }
        dispatch.asyncAfter(deadline : DispatchTime.now() + delayTime , execute : closure)
    }
}
